/**
 * 
 */
package com.exam.daoimpl;

import java.util.List;



import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.exam.dao.IStudentDAO;
import com.exam.model.Student;

/**
 * @author adminpro
 *
 */
@Repository
@Transactional
public class StudentImpl implements IStudentDAO {
	protected SessionFactory sessionFactory;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	/* (non-Javadoc)
	 * @see com.exam.dao.IStudentDAO#getList()
	 */
	@Override
	public List<Student> getList() throws Exception {
		List<Student> lst = null;
		Query query = sessionFactory.openSession().createQuery("From Student");
		lst = (List<Student>)query.list();
		System.out.println(lst.size());
		return lst;
	}

	/* (non-Javadoc)
	 * @see com.exam.dao.IStudentDAO#addStudent(com.exam.model.Student)
	 */
	@Override
	public void addStudent(Student stdObj) throws Exception {		
		sessionFactory.openSession().save(stdObj);	
	}

	/* (non-Javadoc)
	 * @see com.exam.dao.IStudentDAO#updateStudent(com.exam.model.Student)
	 */
	@Override
	public void updateStudent(Student stdObj) throws Exception {
		sessionFactory.openSession().update(stdObj);

	}

}
